# -*- coding:utf-8 -*-
import sys

import cv2 as cv
import numpy as np


if __name__ == '__main__':

    # 灰度图像大律法和三角形法二值化
    img1 = cv.imread(r"E:\studylife\detectflaws\code\imgEnhance\img.jpg", cv.IMREAD_GRAYSCALE)
    _, img1_O = cv.threshold(img1, 250, 255, cv.THRESH_BINARY | cv.THRESH_OTSU)
    _, img1_T = cv.threshold(img1, 250, 255, cv.THRESH_BINARY | cv.THRESH_TRIANGLE)
    cv.imshow('img1', img1)
    cv.imshow('img1_O', img1_O)
    # cv.imshow('img1_T', img1_T)
    # # 灰度图像自适应二值化
    # adaptive_mean = cv.adaptiveThreshold(img1, 255, cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY, 15, 0)
    # adaptive_gauss = cv.adaptiveThreshold(img1, 255, cv.ADAPTIVE_THRESH_GAUSSIAN_C, cv.THRESH_BINARY, 15, 0)
    # cv.imshow('adaptive_mean', adaptive_mean)
    # cv.imshow('adaptive_gauss', adaptive_gauss)
    cv.waitKey(0)
    cv.destroyAllWindows()
